package com.lqian.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lqian.pojo.Employee;
import com.lqian.pojo.Note;
import com.lqian.service.note.NoteService;
import com.lqian.utils.PageUtil;

@Controller
public class NoteController {

	
	@Autowired
	private NoteService noteService;
	
	
	

	@RequestMapping("/leave.do")
	public String leave(Model model,Integer curPage) {
		
		if(curPage == null) {
			 curPage=1;
		}
		//Integer count 总数据数
		int count = noteService.count();
		System.out.println("总数"+count);	
		//Integer pageSize 页面大小
		int pageSize=5;
		//Integer curPage 当前页
		PageUtil page=new PageUtil(count, pageSize, curPage);		
		//List<Employee> list=service.findAllEmp();
		List<Note> list=noteService.findAllNote(page);
		model.addAttribute("list", list);
		model.addAttribute("page", page);
		return "leave.jsp";
	}
	
	
	@RequestMapping("/addLeave.do")
	public String addLeave(Note note,HttpSession session){
		Employee employee =(Employee) session.getAttribute("emp");
		//获取当前请假人的EID
		note.setEid(employee.getEid());
		noteService.applyNote(note);
		return "redirect:leave.do";
	} 
	
	/**
	 * 同意
	 */
	
	@RequestMapping("/agree.do")
	public String agree(Integer nid){
		noteService.agree(nid);
		return "redirect:leave.do";
	}
	
	/**
	 * 打回
	 */
	
	@RequestMapping("/reback.do")
	public String reback(Integer nid){
		noteService.reback(nid);
		return "redirect:leave.do";
	}
	
	/**
	 * 不同意
	 */
	
	@RequestMapping("/disagree.do")
	public String disagree(Integer nid){
		noteService.disagree(nid);
		return "redirect:leave.do";
	}
}
